// pages/theatre/theatre.js
var app=getApp();
Page({
  data:{
    longitude:"",
    latitude:"",
    markers:{},
    controls:[{
      iconPath:'/miniprogram/images/index_disable.png',
      position:{
        left:(app.globalData.windowWidth/2)-11,
        top:((app.globalData.windowHeight-40)/2)-31,
        width:22,
        height:31
      }
    },{
      id:1,
      iconPath:'/miniprogram/images/center.jpg',
      position:{
        left:20,
        top:app.globalData.windowHeight-90,
        width:30,
        height:31
      },
      clickable:true
    }]
  },
  onShow(){
    this.getLocation();
    this.getMessages();
  },
  getMessages(){
    wx.request({
      url: 'https://nuanwan.wekeji.cn/student/index.php/trade/get_list',
      data:{
        distinct:'honghong_course'
      },
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:this.getMessagesSucc.bind(this)
    })
  },
  getMessagesSucc(res){
    console.log(res.data)
    const data=res.data.data;
    const markers=data.map((value,index)=>{
      return {
        id:value.id,
        iconPath:'/images/'+value.type+".jpg",
        longitude:value.longitude,
        latitude:value.latitude,
        width:40,
        height:40
      }
    });
    this.setData({
      markers:markers
    })
  },
  onReady(){
    this.mapCtx=wx.createMapContext('map');
  },
  getLocation(){
    wx.getLocation({
     type:'gcj02',
     success:this.handleGetLocationSucc.bind(this)
    })
  },
  handleGetLocationSucc(res){
    this.setData({
      longitude:res.longitude,
      latitude:res.latitude
    })
  },
  controltap(){
    this.mapCtx.moveToLocation();
  },
  //页面分享
  onShareAppMessage() {
    return{
       title:'萌宠交易平台',
       path:'/pages/index/index'
    }
  },
  handleMarkerTap(e){
    console.log(e);
      wx.navigateTo({
        url:'/pages/detail/detail?id='+e.markerId
    })
  }
  
  })